import bus from "../utils/eventBus"
import { message } from 'antd'
import { paperSizeOptions, printTypeOptions, colorOptions, secretOptions } from "../utils/constant";
const fallBack = {
    getConfigFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getConfigFinished', data)
    },
    importAuthorizeFileFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('importAuthorizeFileFinished', data)
    },
    getUserAuthSecretConfigFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getUserAuthSecretConfigFinished', data)
    },
    setUserAuthSecretConfigFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('setUserAuthSecretConfigFinished', data)
    },
    getPrinterInfoFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getPrinterInfoFinished', data)
    },
    delPrinterInfoFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('delPrinterInfoFinished', data)
    },
    getDefaultPrinterFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getDefaultPrinterFinished', data)
    },
    delNetBurnerInfoFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('delNetBurnerInfoFinished', data)
    },
    getDefaultBurnerFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getDefaultBurnerFinished', data)
    },
    modDefaultBurnerFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('modDefaultBurnerFinished', data)
    },
    modDefaultPrinterFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('modDefaultPrinterFinished', data)
    },
    getNetBurnerInfoFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getNetBurnerInfoFinished', data)
    },
    importNetBurnerCoverFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('importNetBurnerCoverFinished', data)
    },
    addNetBurnerInfoFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('addNetBurnerInfoFinished', data)
    },
    modNetBurnerInfoFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('modNetBurnerInfoFinished', data)
    },
    getNetBurnerCoverTemplateFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getNetBurnerCoverTemplateFinished', data)
    },
    exportNetBurnerCoverFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('exportNetBurnerCoverFinished', data)
    },
    getOpLogListFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getOpLogListFinished', data)
    },
    exportOpLogFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('exportOpLogFinished', data)
    },
    getCarrierLogFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getCarrierLogFinished', data)
    },
    exportCloneLogFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('exportCloneLogFinished', data)
    },
    exportPrintLogFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('exportPrintLogFinished', data)
    },
    getCarrierLogDetailFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getCarrierLogDetailFinished', data)
    },
    delUserFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('delUserFinished', data)
    },
    resetPasswordFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit("resetPasswordFinished", data)
    },
    getDepartmentListFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getDepartmentListFinished', data)
    },
    getUserListFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getUserListFinished', data)
    },
    delDepartmentFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('delDepartmentFinished', data)
    },
    importCardBatchFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('importCardBatchFinished', data)
    },
    getBceCodeStrategyFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getBceCodeStrategyFinished', data)
    },
    enableBceCodeStrategyFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('enableBceCodeStrategyFinished', data)
    },
    delBceCodeStrategyFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('delBceCodeStrategyFinished', data)
    },
    copyBceCodeStrategyFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('copyBceCodeStrategyFinished', data)
    },
    releaseBceCodeStrategyFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('releaseBceCodeStrategyFinished', data)
    },
    updateBceCodeStrategyFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('updateBceCodeStrategyFinished', data)
    },
    getBceCodeStrategyVersionFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getBceCodeStrategyVersionFinished', data)
    },
    getPerStatDetailFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getPerStatDetailFinished', data)
    },
    getPrintRecordFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getPrintRecordFinished', data)
    },
    getPrintRecordDetailFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getPrintRecordDetailFinished', data)
    },
    getCloneRecordFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getCloneRecordFinished', data)
    },
    getCloneRecordDetailFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getCloneRecordDetailFinished', data)
    },
    exportRecoveryLogFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('exportRecoveryLogFinished', data)
    },
    getRecoveryRecordFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getRecoveryRecordFinished', data)
    },
    getRecoveryRecordDetailFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getRecoveryRecordDetailFinished', data)
    },
    modPasswordFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('modPasswordFinished', data)
    },
    modUserFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('modUserFinished', data)
    },
    addUserFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('addUserFinished', data)
    },
    addDepartmentFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('addDepartmentFinished', data)
    },
    modDepartmentFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('modDepartmentFinished', data)
    },
    getUserTreeFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getUserTreeFinished', data)
    },
    setRecoveryConfigFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('setRecoveryConfigFinished', data)
    },
    getRecoveryConfigFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getRecoveryConfigFinished', data)
    },
    getUnrecoveryInfoFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getUnrecoveryInfoFinished', data)
    },
    commitRecoveryFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('commitRecoveryFinished', data)
    },
    getGunDataFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getGunDataFinished', data)
    },
    abortPrintFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('abortPrintFinished', data)
    },
    tryLoginFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('tryLoginFinished', data)
    },
    addBurnFilesInfoNtFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('addBurnFilesInfoNtFinished', data)
    },
    addBurnDirInfoNtFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('addBurnDirInfoNtFinished', data)
    },
    getBurnerListFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getBurnerListFinished', data)
    },
    getNetBurnerListFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getNetBurnerListFinished', data)
    },
    burnSubmitNtFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('burnSubmitNtFinished', data)
    },
    getUserAuthSecretFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getUserAuthSecretFinished', data)
    },
    burnSubmitpProcessNtFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('burnSubmitpProcessNtFinished', data)
        if(data.data.type === 2){
            bus.emit('burnStatusFinished',data)
        }
    },
    getPrintDocTypeFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getPrintDocTypeFinished', data)
    },
    getBceCodeStrategyAttrFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('getBceCodeStrategyAttrFinished', data)
    },
    printConfirmationFinished(res: any) {
        const data = JSON.parse(res)
        console.log(data, "5.3.1、打印信息确认（主动发送）");
        if (data.code !== 200) {
            message.error(data.msg);
            return;
        }
        bus.emit('printConfirmationFinished', data)
    },
    checkAuthorizeFinished(res: any) {
        const data = JSON.parse(res)
        console.log(data, '开机验证授权信息');
        bus.emit('checkAuthorizeFinished',data)
    },
    startPrintFinished(res: any) {
        const data = JSON.parse(res)
        bus.emit('startPrintFinished', data)
    },
    printStatusFinished(res: any) {
        const data = JSON.parse(res);
        console.log(data,'打印进度000')
        if (data.code === 200) {
            const task = {
                ...data,
                currentPartNum: data.currentPartNum, // 当前已打印份数
                currentPage: data.currentPage, // 当前已打印页数
                totalPage: data.totalPage, // 总页数
                printerName: data.printerName, // 打印机名称
                filePath: data.filePath, // PDF绝对路径
                setting: data.setting, // 打印设置（可选）
                fileLevel: data.fileLevel, // 文件密级 1-公开 2-内部 3-秘密 4-机密 5-绝密
                printColorText: colorOptions.find((item) => item.value === data?.printColor)?.label,
                printLayerText: printTypeOptions.find((item) => item.value === data?.printLayer)
                    ?.label,
                fileLevelText: secretOptions.find((item) => item.value === data?.fileLevel)?.label,
                pageSizeText: paperSizeOptions.find((item) => item.value === data?.pageSize)?.label,
                partNum: data.partNum, // 打印总份数
                colorType: data.printColor, // 颜色类型 1-黑白 2-彩色
                layer: data.printLayer, // 打印类型 1-单面 2-双面 4-小册子
                paperType: data.paperType,
                taskId: data.taskId, // 任务ID
                title: data.title,
            };
            bus.emit("printSuccessStatusFinished",task);
        } else {
            message.error(data.msg)
            bus.emit("printErrorStatusFinished",data.taskId);

        }
    }
}
const connect = () => {
    bus.emit('loaded')
    window.chromePro.printStatusFinished.connect(fallBack.printStatusFinished)
    window.chromePro.startPrintFinished.connect(fallBack.startPrintFinished)
    window.chromePro.checkAuthorizeFinished.connect(fallBack.checkAuthorizeFinished)
    window.chromePro.printConfirmationFinished.connect(fallBack.printConfirmationFinished)
    window.chromePro.getBceCodeStrategyAttrFinished.connect(fallBack.getBceCodeStrategyAttrFinished)
    window.chromePro.getPrintDocTypeFinished.connect(fallBack.getPrintDocTypeFinished)
    window.chromePro.burnSubmitpProcessNtFinished.connect(fallBack.burnSubmitpProcessNtFinished)
    window.chromePro.getUserAuthSecretFinished.connect(fallBack.getUserAuthSecretFinished)
    window.chromePro.burnSubmitNtFinished.connect(fallBack.burnSubmitNtFinished)
    window.chromePro.getNetBurnerListFinished.connect(fallBack.getNetBurnerListFinished)
    window.chromePro.getBurnerListFinished.connect(fallBack.getBurnerListFinished)
    window.chromePro.addBurnDirInfoNtFinished.connect(fallBack.addBurnDirInfoNtFinished)
    window.chromePro.addBurnFilesInfoNtFinished.connect(fallBack.addBurnFilesInfoNtFinished)
    window.chromePro.tryLoginFinished.connect(fallBack.tryLoginFinished)
    window.chromePro.abortPrintFinished.connect(fallBack.abortPrintFinished)
    window.chromePro.getGunDataFinished.connect(fallBack.getGunDataFinished)
    window.chromePro.commitRecoveryFinished.connect(fallBack.commitRecoveryFinished)
    window.chromePro.getUnrecoveryInfoFinished.connect(fallBack.getUnrecoveryInfoFinished)
    window.chromePro.getRecoveryConfigFinished.connect(fallBack.getRecoveryConfigFinished)
    window.chromePro.setRecoveryConfigFinished.connect(fallBack.setRecoveryConfigFinished)
    window.chromePro.getUserTreeFinished.connect(fallBack.getUserTreeFinished)
    window.chromePro.modDepartmentFinished.connect(fallBack.modDepartmentFinished)
    window.chromePro.addDepartmentFinished.connect(fallBack.addDepartmentFinished)
    window.chromePro.addUserFinished.connect(fallBack.addUserFinished)
    window.chromePro.modUserFinished.connect(fallBack.modUserFinished)
    window.chromePro.modPasswordFinished.connect(fallBack.modPasswordFinished)
    window.chromePro.getRecoveryRecordDetailFinished.connect(fallBack.getRecoveryRecordDetailFinished)
    window.chromePro.getRecoveryRecordFinished.connect(fallBack.getRecoveryRecordFinished)
    window.chromePro.exportRecoveryLogFinished.connect(fallBack.exportRecoveryLogFinished)
    window.chromePro.getCloneRecordDetailFinished.connect(fallBack.getCloneRecordDetailFinished)
    window.chromePro.getCloneRecordFinished.connect(fallBack.getCloneRecordFinished)
    window.chromePro.getPrintRecordDetailFinished.connect(fallBack.getPrintRecordDetailFinished)
    window.chromePro.getPrintRecordFinished.connect(fallBack.getPrintRecordFinished)
    window.chromePro.getPerStatDetailFinished.connect(fallBack.getPerStatDetailFinished)
    window.chromePro.getBceCodeStrategyVersionFinished.connect(fallBack.getBceCodeStrategyVersionFinished)
    window.chromePro.updateBceCodeStrategyFinished.connect(fallBack.updateBceCodeStrategyFinished)
    window.chromePro.releaseBceCodeStrategyFinished.connect(fallBack.releaseBceCodeStrategyFinished)
    window.chromePro.copyBceCodeStrategyFinished.connect(fallBack.copyBceCodeStrategyFinished)
    window.chromePro.delBceCodeStrategyFinished.connect(fallBack.delBceCodeStrategyFinished)
    window.chromePro.enableBceCodeStrategyFinished.connect(fallBack.enableBceCodeStrategyFinished)
    window.chromePro.getBceCodeStrategyFinished.connect(fallBack.getBceCodeStrategyFinished)
    window.chromePro.importCardBatchFinished.connect(fallBack.importCardBatchFinished)
    window.chromePro.delDepartmentFinished.connect(fallBack.delDepartmentFinished)
    window.chromePro.getUserListFinished.connect(fallBack.getUserListFinished)
    window.chromePro.getDepartmentListFinished.connect(fallBack.getDepartmentListFinished)
    window.chromePro.delUserFinished.connect(fallBack.delUserFinished)
    window.chromePro.resetPasswordFinished.connect(fallBack.resetPasswordFinished)
    window.chromePro.getCarrierLogDetailFinished.connect(fallBack.getCarrierLogDetailFinished)
    window.chromePro.exportPrintLogFinished.connect(fallBack.exportPrintLogFinished)
    window.chromePro.exportCloneLogFinished.connect(fallBack.exportCloneLogFinished)
    window.chromePro.getCarrierLogFinished.connect(fallBack.getCarrierLogFinished)
    window.chromePro.getConfigFinished.connect(fallBack.getConfigFinished)
    window.chromePro.importAuthorizeFileFinished.connect(fallBack.importAuthorizeFileFinished)
    window.chromePro.getUserAuthSecretConfigFinished.connect(fallBack.getUserAuthSecretConfigFinished)
    window.chromePro.setUserAuthSecretConfigFinished.connect(fallBack.setUserAuthSecretConfigFinished)
    window.chromePro.getPrinterInfoFinished.connect(fallBack.getPrinterInfoFinished)
    window.chromePro.delPrinterInfoFinished.connect(fallBack.delPrinterInfoFinished)
    window.chromePro.getDefaultPrinterFinished.connect(fallBack.getDefaultPrinterFinished)
    window.chromePro.delNetBurnerInfoFinished.connect(fallBack.delNetBurnerInfoFinished)
    window.chromePro.getDefaultBurnerFinished.connect(fallBack.getDefaultBurnerFinished)
    window.chromePro.modDefaultBurnerFinished.connect(fallBack.modDefaultBurnerFinished)
    window.chromePro.modDefaultPrinterFinished.connect(fallBack.modDefaultPrinterFinished)
    window.chromePro.getNetBurnerInfoFinished.connect(fallBack.getNetBurnerInfoFinished)
    window.chromePro.importNetBurnerCoverFinished.connect(fallBack.importNetBurnerCoverFinished)
    window.chromePro.addNetBurnerInfoFinished.connect(fallBack.addNetBurnerInfoFinished)
    window.chromePro.modNetBurnerInfoFinished.connect(fallBack.modNetBurnerInfoFinished)
    window.chromePro.getNetBurnerCoverTemplateFinished.connect(fallBack.getNetBurnerCoverTemplateFinished)
    window.chromePro.exportNetBurnerCoverFinished.connect(fallBack.exportNetBurnerCoverFinished)
    window.chromePro.getOpLogListFinished.connect(fallBack.getOpLogListFinished)
    window.chromePro.exportOpLogFinished.connect(fallBack.exportOpLogFinished)

}
export { connect }